package com.example.job.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.util.Date;

/**
 * @author chentao
 * @version 1.0
 * @description: TODO
 * @date 2025/3/26 下午11:03
 */
@Data
@TableName(value = "sys_job")
public class SysJob extends Model<SysJob> {

    //主键
    @TableId(type = IdType.AUTO)
    private Long id;

    //名称
    @TableField(value = "name")
    private String name;

    //执行类
    @TableField(value = "job_class")
    private String jobClass;

    //状态
    @TableField(value = "status")
    private boolean status;

    //cron表达式
    @TableField(value = "cron")
    private String cron;

    //下次运行时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "next_run_time")
    private Date nextRunTime;

    //额外参数
    @TableField(value = "extra_parameter")
    private String extraParameter;

    //是否取消执行
    @TableField(value = "canceled")
    private boolean canceled;

    //是否取消执行
    @TableField(value = "auto_delete")
    private boolean autoDelete;

    //创建时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "create_time")
    private Date createTime;

    //更新时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "update_time")
    private Date updateTime;

    public void recalculateFields() {
        if (this.createTime == null) {
            this.createTime = new Date();
        }
        this.updateTime = new Date();
    }
}
